import { useDictStore, DictData } from "@/store/modules/dict";
import { getDict as apiGetDict } from "@/api/dict";
import { DictForm } from "@/api/dict/types";

export function getDict(...args: string[]) {
  const dict = useDictStore();
  apiGetDict(args).then(({ data }) => {
    Object.keys(data).forEach((key) => {
      //dict[key] = data[key];
      const tmpData: DictData[] = [];
      data[key].forEach((item: DictForm) => {
        tmpData.push({
          title: item.dictLabel,
          label: item.dictLabel,
          value: item.dictValue,
          cssClass: item.listClass,
        });
      });
      dict.setDict(key, tmpData);
    });
  });

  return dict.dict;
}
